package com.study.spring.bean;

import com.study.spring.model.Member;
import org.springframework.beans.BeanWrapper;
import org.springframework.beans.BeanWrapperImpl;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition;

/**
 * [【小家Spring】Spring IoC是如何使用BeanWrapper和Java内省结合起来给Bean属性赋值的 \- 掘金](https://juejin.im/post/5d2d24c45188252bf36f1a7d)
 *[【小家Spring】聊聊Spring中的数据绑定 \-\-\- BeanWrapper以及内省Introspector和PropertyDescriptor \- 掘金](https://juejin.im/post/5d2c545f5188252f567a7264)
 * [Spring3\.1\.0实现原理分析\(四\)\.属性访问器\(PropertyAccessor\) \- roberts939299的专栏 \- CSDN博客](https://blog.csdn.net/roberts939299/article/details/70599506)
 * */
public class bean属性填充 {
    public static void main(String[] args) {
        //1. MutablePropertyValues
        MutablePropertyValues properties=new MutablePropertyValues();
        properties.add("memberId", "12345");
        RootBeanDefinition definition=new RootBeanDefinition(Member.class,properties);
        DefaultListableBeanFactory factory=new DefaultListableBeanFactory();
        factory.registerBeanDefinition("member", definition);
        Member member = factory.getBean(Member.class);
        System.out.println(member.getMemberId());

        //2. BeanWrapper
        BeanWrapper beanWrapper = new BeanWrapperImpl(Member.class);
        beanWrapper.setPropertyValue("memberId", "234");
        member = (Member) beanWrapper.getWrappedInstance();
        System.out.println(member.getMemberId());

        //3 PropertyEditor

        //PropertyAccessor
    }
}
